﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.vo;
using Business.exception;

namespace Business.dao
{
    internal class NewsDao : AbstractDao
    {

        public News GetById(Int32 id)
        {
            News news = null;

            try
            {
                news = mapper.QueryForObject<News>("News.selectById", id);

            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving user from database", ex);
            }

            return news;
        }

        public IList<News> GetAll()
        {
            IList<News> news = null;

            try
            {
                news = mapper.QueryForList<News>("News.selectAll", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }

            return news;
        }

        public void Save(News news)
        {
            try
            {
                mapper.Insert("News.insert", news);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }


        public void Update(News news)
        {
            try
            {
                mapper.Update("News.update", news);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }

        public void Delete(Int32 id)
        {
            try
            {
                mapper.Delete("News.deleteById", id);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving users from database", ex);
            }
        }
    }
}
